package com.srxz.mobilepharmacy.controller;

import com.alibaba.fastjson.JSON;
import com.srxz.mobilepharmacy.entity.UserInfoPK;
import com.srxz.mobilepharmacy.util.SessionTool;
import com.srxz.mobilepharmacy.util.back.BackMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestControllerAdvice
@Slf4j
public class ExceptionController {

    @ExceptionHandler({Exception.class})
    public BackMessage handException(HttpServletRequest request , HttpSession session, Exception e) throws Exception{
        UserInfoPK uid = SessionTool.getUser(session);
       // Integer msn = SessionTool.getHouse(session);
        e.printStackTrace();
        BackMessage backMessage = BackMessage.serverException(e.getMessage());
        log.error(JSON.toJSONString(uid)+"\t"+JSON.toJSONString(e));
        return backMessage;
    }
}
